import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class MatchPage extends Utils {
    private static String url = "http://8.137.60.68:9091/gobang_login.html";
    public MatchPage() {
        super(url);
    }

    // 查看匹配按钮功能是否正常
    public void match() {

        // 先登录
        driver.navigate().refresh();
        driver.findElement(By.cssSelector("#username")).sendKeys("admin");
        driver.findElement(By.cssSelector("#password")).sendKeys("admin");
        driver.findElement(By.cssSelector("#submit")).click();

        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
        WebElement el = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#match-button")));
        assert el.getText().equals("开始匹配");

        driver.findElement(By.cssSelector("#match-button")).click();
        wait.until(ExpectedConditions.textToBe(By.cssSelector("#match-button"), "匹配中...(点击停止)"));
        assert el.getText().equals("匹配中...(点击停止)");

        driver.findElement(By.cssSelector("#match-button")).click();
        wait.until(ExpectedConditions.textToBe(By.cssSelector("#match-button"), "开始匹配"));
        assert el.getText().equals("开始匹配");

    }
}
